﻿using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppPipeio
{
    class Program
    {
        static void Main(string[] args)
        {
            new PipeServer();
            Console.WriteLine("HAHA");
            Console.ReadLine();
        }
    }

    sealed class PipeServer
    {
        private readonly NamedPipeServerStream m_pipe = new NamedPipeServerStream("Echo", PipeDirection.InOut, -1,
            PipeTransmissionMode.Message, PipeOptions.Asynchronous | PipeOptions.WriteThrough);

        public PipeServer()
        {
            m_pipe.WaitForConnection();
            m_pipe.BeginWaitForConnection(ClientConnected, null);
        }

        private void ClientConnected(IAsyncResult result)
        {
            new PipeServer();
            m_pipe.EndWaitForConnection(result);

            byte[] data = new byte[1000];
            m_pipe.BeginRead(data, 0, data.Length, GoRequest, data);
        }

        private void GoRequest(IAsyncResult result)
        {
            throw new NotImplementedException();
        }
    }
}
